package com.erqi.dao.impl;

import com.erqi.dao.sqlServerDao;
import com.erqi.mapper.second.SqlServerPlcDataMapper;
import com.erqi.pojo.Qrandplc;
import com.erqi.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author king
 * @Date 2020/8/31 09:12
 * @Version 1.0
 * 处理 sqlServer 数据库操作
 */
@Service
public class sqlServerDaoImpl implements sqlServerDao {

    @Autowired
    SqlServerPlcDataMapper sqlServerPlcDataMapper;
    SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);


    @Override
    public int SavePLCData(Qrandplc Qrandplc) {
        Qrandplc.setId(idWorker.nextId());
       return sqlServerPlcDataMapper.insertSelective(Qrandplc);
    }

    /**
     * 入库之前检查之前是否已有数据如果有数据返回 1（如果已经存在数据，吧之前的数据 状态更变为重复） 无数据返回 0（无数据直接入库）
     * 11.12更新 反之上面
     * @param type
     * @param code
     * @return
     */
    @Override
    public int checkPLCData_sqlServer(String type, String code) {
        List<Qrandplc> select = sqlServerPlcDataMapper.select(type, code, "入库成功");
        if (select.size()<=0){
            return 0;
        }else{
            return 1;
        }
    }

}
